package com.soap.client;

import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.axis.AxisFault;

import cn.com.tech_trans.www.CRM_VIP_ProxyLocator;
import cn.com.tech_trans.www.CRM_VIP_ProxySoapStub;
import cn.com.tech_trans.www.RequestDataOfVipInfoRequest;
import cn.com.tech_trans.www.RequestHeader;
import cn.com.tech_trans.www.ResponseDataOfListOfVIP;
import cn.com.tech_trans.www.VipInfoRequest;

import com.soap.constants.SoapConstants;
import com.soap.util.AESUtil;
import com.soap.util.MD5Util;

public class ClientTest {

	public static void main(String[] args) throws Exception {
		Date currentDate = new Date();
		String reqDate = new SimpleDateFormat("yyyyMMdd").format(currentDate);

		String reqTime = new SimpleDateFormat("HHmmss").format(currentDate);

		String sign = MD5Util.md5Encode(reqDate + reqTime
				+ SoapConstants.REQEUST_SIGN);

		RequestDataOfVipInfoRequest request = new RequestDataOfVipInfoRequest();
		RequestHeader header = new RequestHeader();
		header.setREQDATE(reqDate);
		header.setREQTIME(reqTime);
		header.setSIGN(sign);
		request.setHeader(header);
		
		VipInfoRequest data = new VipInfoRequest();
		data.setVipcode(AESUtil
				.encrypt("122333", SoapConstants.REQEUST_SIGN));
		request.setData(data);

		try {
			CRM_VIP_ProxyLocator service = new CRM_VIP_ProxyLocator();
			
			URL endpointURL = new URL(SoapConstants.REQEUST_WSDL_URL);
			CRM_VIP_ProxySoapStub stub = new CRM_VIP_ProxySoapStub(endpointURL,
					service);
			ResponseDataOfListOfVIP vip = stub.getVipInfo(request);

			System.out.println(vip);
			
		} catch (AxisFault e) {
			e.printStackTrace();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		}

	}
}
